<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j">

<ui:composition template="../templates/popup.xhtml">
	<ui:define name="titre">#{lbl['menu.hub.departure']}</ui:define>
	<ui:define name="popup_page">

		<!-- Fonctions javascript. -->
		<script language="javascript">
			function javascriptOnLoad(){
					self.opener.refreshHub();
				}

			// Juste pour le visuel, en fait, la donnée 
			// a déjà été copiée dans le champ par la 
			// fonction de vérification des voies.
			function copyRailFormation(rail, idx){
				var oRail = document.getElementById(rail);
				if(oRail){
					oRail.selectedIndex = idx;
					}
				}
		</script>

		<!-- La légende pour les départs. -->
		<ui:include src="../blocs/inc_departure_legend.xhtml" />

		<a4j:outputPanel id="departure_panel">
			<!-- La liste des erreurs. -->
			<rich:messages />

			<h:form id="departure_form">
				<h:panelGrid style="width:100%;height:390px;"
					columnClasses="_left_top">
					<rich:dataTable id="departure_table" style="width:100%"
						value="#{hubManaged.lstSillons}" var="sillon"
						rowClasses="rich_datagrid_even_line, rich_datagrid_odd_line"
						styleClass="stable" iterationStatusVar="it" rows="10">

						<f:facet name="noData">
						&nbsp;<h:outputText value="#{msg['msg.info.nodata']}"
								style="font-size:12px" />
						</f:facet>

						<rich:column style="width:35px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.id']}" />
							</f:facet>
							<h:outputText value="#{sillon.extId}" />
						</rich:column>

						<rich:column style="width:110px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.train.id']}" />
							</f:facet>
							<h:outputText value="#{sillon.tcmsTrainId}" />
						</rich:column>

						<rich:column style="width:45px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.train.lading']}" />
							</f:facet>
							<h:outputText value="#{sillon.lading}" />
							<h:outputText value="#{lbl['common.nc']}"
								rendered="#{sillon.lading == null}" />
						</rich:column>

						<rich:column style="width:100px;text-align:left;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.destination']}" />
							</f:facet>
							<h:outputText value="#{sillon.destination}" />
						</rich:column>

						<rich:column style="width:60px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.nb.wagon']}" />
							</f:facet>
							<h:outputText value="#{lbl['common.nc']}"
								rendered="#{sillon.nbWagons == 0}" />
							<h:outputText value="#{sillon.nbWagons}"
								rendered="#{sillon.nbWagons ne 0}" />
						</rich:column>

						<rich:column style="width:60px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.departure.theo.date']}" />
							</f:facet>
							<h:outputText value="#{sillon.movementDate}">
								<f:convertDateTime pattern="dd/MM/yyyy" timeZone="Europe/Paris" />
							</h:outputText>
						</rich:column>

						<rich:column style="width:90px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.departure.theo.time']}" />
							</f:facet>
							<h:outputText value="#{sillon.movementTime}" />
						</rich:column>

						<rich:column style="width:80px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.departure.real.date']}" />
							</f:facet>
							<rich:calendar inputSize="10" value="#{sillon.realMovementDate}"
								todayControlMode="hidden" datePattern="dd/MM/yyyy"
								showFooter="false"
								disabled="#{sillon.statusId==2 || sillon.statusId==10 
								|| sillon.statusId==11 || sillon.statusId==12}">
							</rich:calendar>
						</rich:column>

						<rich:column style="width:80px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.departure.real.time']}" />
							</f:facet>
							<h:inputText value="#{sillon.realMovementTime}" size="5"
								maxlength="5" onkeypress="return checkTime(this);"
								disabled="#{sillon.statusId==2 || sillon.statusId==10 
								|| sillon.statusId==11 || sillon.statusId==12}" />
						</rich:column>

						<rich:column style="text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.formation.rail']}" />
							</f:facet>
							<h:selectOneMenu id="railFormationId"
								disabled="#{sillon.statusId==10 || sillon.statusId==11 
								|| sillon.statusId==12 || sillon.statusId==13}"
								onchange="checkFormationRail(#{it.index}, 3, this.value); 
								copyRailFormation('departure_form:departure_table:#{it.index}:railId', this.selectedIndex);"
								value="#{sillon.railFormationId}">
								<f:selectItems value="#{repositoryManaged.lstAllRails}" />
							</h:selectOneMenu>
						</rich:column>

						<rich:column style="text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.departure.rail']}" />
							</f:facet>
							<h:selectOneMenu id="railId" value="#{sillon.railId}"
								onchange="checkDepartureRail(#{it.index}, 4, this.value);"
								disabled="#{sillon.statusId==10 || sillon.statusId==11 
								|| sillon.statusId==12 || sillon.statusId==13}">
								<f:selectItems value="#{repositoryManaged.lstAllRails}" />
							</h:selectOneMenu>
						</rich:column>

						<rich:column style="text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['common.comment']}" />
							</f:facet>
							<a4j:commandLink execute="@this" render="sillon_comment_panel"
								oncomplete="centerPopup(380, 180, 'sillon_comment_div');
								display_div(true,'sillon_comment_div');makeFocusOnField('departure_form:comment');">
								<h:graphicImage value="../../imgs/icons/ico_comment.png"
									width="30" rendered="#{!sillon.commentFilled}" />

								<h:graphicImage value="../../imgs/icons/ico_comment_filled.png"
									width="30" rendered="#{sillon.commentFilled}" />
								<f:setPropertyActionListener
									target="#{hubManaged.currentSillon}" value="#{sillon}" />
							</a4j:commandLink>
						</rich:column>

						<rich:column style="width:60px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.departure.plan']}" />
							</f:facet>

							<!-- Plan de formation à effectuer. -->
							<a4j:commandLink execute="@this" rendered="#{sillon.statusId==2}"
								action="#{hubManaged.getFormationPlanPhaseOne}">
								<f:setPropertyActionListener
									target="#{hubManaged.currentSillon}" value="#{sillon}" />
								<h:graphicImage value="../../imgs/icons/ico_plan.png" width="30" />
							</a4j:commandLink>

							<!-- Plan de formation à passer Terminé. -->
							<a4j:commandLink execute="@this" render="departure_table"
								oncomplete="self.opener.refreshHub();"
								action="#{hubManaged.completeFormationPlan}"
								rendered="#{sillon.statusId==10}">
								<f:setPropertyActionListener
									target="#{hubManaged.currentSillon}" value="#{sillon}" />
								<h:graphicImage value="../../imgs/icons/ico_plan_process.png"
									width="30" />
							</a4j:commandLink>

							<!-- Plan de formation à passer terminé. -->
							<h:graphicImage value="../../imgs/icons/ico_plan_complete.png"
								width="30"
								rendered="#{sillon.statusId==11 || sillon.statusId==12 
								|| sillon.statusId==13}" />
						</rich:column>

						<rich:column style="text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.departure.sens']}" />
							</f:facet>
							<h:selectOneMenu id="stack"
								onchange="reverseSense(#{it.index}, this.value);"
								disabled="#{sillon.statusId==2 || sillon.statusId==10 
								|| sillon.statusId==11 || sillon.statusId==12}">
								<f:selectItem itemLabel="#{lbl['common.south']}"
									itemValue="false" />
								<f:selectItem itemLabel="#{lbl['common.north']}"
									itemValue="true" />
							</h:selectOneMenu>
						</rich:column>

						<rich:column style="width:70px;text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['sillon.departure']}" />
							</f:facet>

							<!-- Train à positionner sur départ mais formation non effectuée. -->
							<h:graphicImage
								value="../../imgs/icons/ico_validate_disabled.png" width="25"
								rendered="#{sillon.statusId==2 || sillon.statusId==10}" />

							<!-- Train à positionner sur la voie de départ. -->
							<a4j:commandLink execute="@form" render="departure_table"
								action="#{hubManaged.requestDeparture}"
								oncomplete="self.opener.refreshHub();"
								rendered="#{sillon.statusId==11}">
								<f:setPropertyActionListener
									target="#{hubManaged.currentSillon}" value="#{sillon}" />
								<h:graphicImage value="../../imgs/icons/ico_validate.png"
									width="25" />
							</a4j:commandLink>

							<!-- Train placer à l'état "Prêt au départ". -->
							<a4j:commandLink execute="@this" render="departure_table"
								action="#{hubManaged.processDeparture}"
								oncomplete="self.opener.refreshHub();"
								rendered="#{sillon.statusId==12}">
								<f:setPropertyActionListener
									target="#{hubManaged.currentSillon}" value="#{sillon}" />
								<h:graphicImage value="../../imgs/icons/ico_validate_ready.png"
									width="25" />
							</a4j:commandLink>

							<!-- Train à faire partir. -->
							<a4j:commandLink execute="@form" render="departure_table"
								action="#{hubManaged.completeDeparture}"
								oncomplete="self.opener.refreshHub();"
								rendered="#{sillon.statusId==13}">
								<f:setPropertyActionListener
									target="#{hubManaged.currentSillon}" value="#{sillon}" />
								<h:graphicImage
									value="../../imgs/icons/ico_validate_complete.png" width="25" />
							</a4j:commandLink>
						</rich:column>

						<!-- Annulation du train au départ. -->
						<rich:column style="text-align:center;">
							<f:facet name="header">
								<h:outputText value="#{lbl['common.delete']}" />
							</f:facet>
							<a4j:commandLink execute="@this" render="confirm_del_popup"
								oncomplete="#{rich:component('confirm_del_popup')}.show()">
								<h:graphicImage value="../../imgs/icons/ico_delete.png"
									width="25" />
								<f:setPropertyActionListener
									target="#{hubManaged.currentSillon}" value="#{sillon}" />
							</a4j:commandLink>
						</rich:column>

						<f:facet name="footer">
							<rich:dataScroller page="#{hubManaged.page}" />
						</f:facet>
					</rich:dataTable>
				</h:panelGrid>

				<!-- Bouton de fermeture. -->
				<h:panelGrid style="width:100%" columnClasses="_center">
					<h:commandButton value="#{lbl['common.button.close']}"
						onclick="self.opener.releaseOneWindow();self.close();" />
				</h:panelGrid>

				<!-- Pilotage des lignes tableau. -->
				<ui:include src="../blocs/inc_selector.xhtml" />

				<!-- Panneau de saisie commentaire. -->
				<ui:include src="../blocs/inc_sillon_comment.xhtml" />

				<!-- ********************************* -->
				<!-- Popup pour la suppression sillon. -->
				<rich:popupPanel id="confirm_del_popup"
					headerClass="rich_panel_popup_head"
					header="#{lbl['sillon.confirm']}" autosized="true">
					<h:panelGrid styleClass="panel" width="430" height="90"
						id="del_panel">
						<h:panelGroup>
							<h:outputText value="#{msg['msg.confirm.sillon.delete']}" /> :  
							<h:outputText value="#{hubManaged.currentSillon.extId}" /> ?
						</h:panelGroup>
						<h:panelGrid columns="3" columnClasses="_left, _center, _right"
							width="100%" style="margin-top:20px">
							<a4j:commandButton id="sillon_b_cancel_delete"
								value="#{lbl['common.button.cancel']}"
								onclick="#{rich:component('confirm_del_popup')}.hide(); return false;" />

							<a4j:commandButton id="sillon_b_init"
								action="#{hubManaged.initSillon}" render="departure_panel"
								execute="@this" value="#{lbl['common.button.init']}"
								onclick="#{rich:component('confirm_del_popup')}.hide();"
								oncomplete="self.opener.refreshHub();" />

							<a4j:commandButton id="sillon_b_delete"
								action="#{hubManaged.deleteSillon}" render="departure_panel"
								execute="@this" value="#{lbl['common.button.delete']}"
								onclick="#{rich:component('confirm_del_popup')}.hide();"
								oncomplete="self.opener.refreshHub();" />
						</h:panelGrid>
					</h:panelGrid>
				</rich:popupPanel>

				<!-- ******************************************************* -->
				<!-- Méthode pour le contrôle simple de la voie à formation. -->
				<a4j:jsFunction name="checkFormationRail" execute="@this"
					action="#{hubManaged.checkRail}">
					<a4j:param name="idx" assignTo="#{hubManaged.criterion.idx}" />
					<a4j:param name="typeCheckRail"
						assignTo="#{hubManaged.criterion.typeCheckRail}" />
					<a4j:param name="posRailId"
						assignTo="#{hubManaged.criterion.posRailId}" />
				</a4j:jsFunction>

				<!-- ******************************************************* -->
				<!-- Méthode pour le contrôle simple de la voie au départ. -->
				<a4j:jsFunction name="checkDepartureRail" execute="@this"
					action="#{hubManaged.checkRail}">
					<a4j:param name="idx" assignTo="#{hubManaged.criterion.idx}" />
					<a4j:param name="typeCheckRail"
						assignTo="#{hubManaged.criterion.typeCheckRail}" />
					<a4j:param name="posRailId"
						assignTo="#{hubManaged.criterion.posRailId}" />
				</a4j:jsFunction>

				<!-- ********************************************* -->
				<!-- Méthode pour l'inversion de sens au départ. -->
				<a4j:jsFunction name="reverseSense" execute="@this" immediate="true"
					action="#{hubManaged.reverseSense}">
					<a4j:param name="idx" assignTo="#{hubManaged.criterion.idx}" />
					<a4j:param name="reverseSense"
						assignTo="#{hubManaged.criterion.reverseSense}" />
				</a4j:jsFunction>
			</h:form>
		</a4j:outputPanel>
	</ui:define>
</ui:composition>
</html>